﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@using FastCodeGeneration.Models
@model FastCodeGeneration.Models.ModuleViewModel
@{
    Layout = null;
}

<!doctype html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="icon" href="../dist/img/favicon-32x32.png" sizes="32x32" type="image/png">
    <link rel="icon" href="../dist/img/favicon-16x16.png" sizes="16x16" type="image/png">
    <meta name="keywords" content="响应式后台模板,开源免费后台模板,Bootstrap5后台管理系统模板">
    <meta name="description" content="bootstrap-admin基于bootstrap5的免费开源的响应式后台管理模板">
    <meta name="author" content="ajiho">
    <link href="~/lib/bootstrap-icons/font/bootstrap-icons.min.css" rel="stylesheet" />
    <link href="~/lib/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/lib/bootstrap-select/dist/css/bootstrap-select.min.css" rel="stylesheet" />
    <link href="~/css/bootstrap-admin.css" rel="stylesheet" />
    <title>bootstrap-admin开源免费响应式后台管理系统模板</title>
</head>
<body class="bg-body-tertiary py-3">
    <div class="container-fluid">
        <div class="card border-0 shadow-sm">
            <div class="card-body">
                <form id="form">
                    <input id="id" name="id" value="@Model.Entity.Id" hidden />
                    <div class="mb-3">
                        <label for="projectId" class="col-sm-auto col-form-label">项目</label>
                        <div class="col">
                            <select class="selectpicker" id="projectId" name="projectId">
                                @foreach (var item in Model.Projects)
                                {
                                    if (item.Id == @Model.Entity.ProjectId)
                                    {
                                        <option value="@item.Id" selected>@item.Name</option>
                                    }
                                    else
                                    {
                                        <option value="@item.Id">@item.Name</option>
                                    }
                                }
                            </select>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label for="name" class="form-label">模块名</label>
                        <input type="text" class="form-control" id="name" name="name" value="@Model.Entity.Name">
                    </div>
                    <div class="mb-3">
                        <label for="tablePrefix" class="form-label">表前缀</label>
                        <input type="text" class="form-control" id="tablePrefix" name="tablePrefix" value="@Model.Entity.TablePrefix">
                    </div>

                    <div class="mb-3">
                        <label for="modulePath" class="form-label">模块路径</label>
                        <input type="text" class="form-control" id="modulePath" name="modulePath" value="@Model.Entity.ModulePath">
                    </div>

                    <div class="mb-3">
                        <label for="fileIgnorePrefix" class="col-sm-auto col-form-label">生成的文件是否忽略表前缀</label>
                        <div class="col">
                            <select class="selectpicker" id="fileIgnorePrefix" name="fileIgnorePrefix">
                                @if (Model.Entity.FileIgnorePrefix)
                                {
                                    <option value="1" selected>是</option>
                                    <option value="0">否</option>
                                }
                                else
                                {
                                    <option value="1">是</option>
                                    <option value="0" selected>否</option>
                                }
                            </select>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label for="domainFolder" class="form-label">domain文件夹名</label>
                        <input type="text" class="form-control" id="domainFolder" name="domainFolder"
                               value="@(string.IsNullOrEmpty(Model.Entity.DomainFolder) ? "domain" : Model.Entity.DomainFolder)">
                    </div>

                    <div class="mb-3">
                        <label for="mapperFolder" class="form-label">mapper文件夹名</label>
                        <input type="text" class="form-control" id="mapperFolder" name="mapperFolder"
                               value="@(string.IsNullOrEmpty(Model.Entity.MapperFolder) ? "mapper" : Model.Entity.MapperFolder)">
                    </div>
                    <div class="mb-3">
                        <label for="serviceFolder" class="form-label">service文件夹名</label>
                        <input type="text" class="form-control" id="serviceFolder" name="serviceFolder"
                               value="@(string.IsNullOrEmpty(Model.Entity.ServiceFolder) ? "service" : Model.Entity.ServiceFolder)">
                    </div>
                    <div class="mb-3">
                        <label for="controllerFolder" class="form-label">controller文件夹名</label>
                        <input type="text" class="form-control" id="controllerFolder" name="controllerFolder"
                               value="@(string.IsNullOrEmpty(Model.Entity.ControllerFolder) ? "controller" : Model.Entity.ControllerFolder)">
                    </div>

                    @if (Model.Entity.Id == null)
                    {
                        <button type="submit" class="btn btn-primary">添加</button>
                    }
                    else
                    {
                        <button type="submit" class="btn btn-primary">修改</button>
                    }

                </form>
            </div>
        </div>


    </div>
    <!--回到顶部开始-->
    <a href="javaScript:" class="bsa-back-to-top"><i class='bi bi-arrow-up-short'></i></a>
    <!--回到顶部结束-->


    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/formvalidation/js/formvalidation.js"></script>
    <script src="~/lib/formvalidation/js/framework/bootstrap.js"></script>
    <script src="~/lib/formvalidation/js/language/zh_CN.js"></script>
    <script src="~/lib/bootstrap-select/dist/js/bootstrap-select.min.js"></script>
    <script src="~/lib/bootstrap-select/dist/js/i18n/defaults-zh_cn.min.js"></script>
    <script src="~/lib/mark/marked.js"></script>
    <script src="~/js/bootstrap-admin.js"></script>
    <script src="~/js/app.js"></script>
    <script>

        $("#form").formValidation({
            //验证字段
            fields: {
                name: { validators: { notEmpty: true } },
                modulePath: { validators: { notEmpty: true } },
                domainFolder: { validators: { notEmpty: true } },
                mapperFolder: { validators: { notEmpty: true } },
                serviceFolder: { validators: { notEmpty: true } },
                controllerFolder: { validators: { notEmpty: true } }
            }
        }).on('success.form.fv', function (e) {
            //阻止表单提交
            e.preventDefault();
            //得到表单对象
            let $form = $(e.target);
            let data = $form.serialize();

            //得到序列化数据
            $.ajax({
                url: "/Module/Save",
                method: 'post',
                data: data,
                success: function (res) {
                    //添加成功
                    $.toasts({
                        type: 'success',
                        content: '修改成功',
                        delay: 1000,
                        autohide: true,
                        onHidden: function () {
                            parent.modalInstance.setData(true);
                            parent.modalInstance.close();
                        }
                    })

                }
            })

        });


    </script>

</body>
</html>
